package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.*;
import com.lyf.scm.admin.api.dto.es.SalesPlanEsEntity;
import com.lyf.scm.admin.domain.remote.allocationservice.SalesPlanEsRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 销售计划Es查询通用解决方案远程接口
 *
 * @author wangchlei
 * @date 2020/11/06
 */
@Service
@Slf4j
public class SalesPlanEsFacade {
    @Resource
    private SalesPlanEsRemote salesPlanEsRemote;

    public PageInfo<EsReturnDTO> queryByGroup(EsAggregationDTO esAggregation) {
        log.info("按条件查询:esAggregation:{}", JSON.toJSONString(esAggregation));
        Response<PageInfo<EsReturnDTO>> response = salesPlanEsRemote.queryByGroup(esAggregation);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public List<SalesPlanEsEntity> listPageQuery(EsQueryDTO esQuery, Integer pageNum, Integer pageSize) {
        Response<List<SalesPlanEsEntity>> response = salesPlanEsRemote.listPageQuery(esQuery,pageNum,pageSize);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public EsScrollReturnDTO exportByGroup(EsExportAggregationDTO esExportAggregationDTO) {
        log.info("按条件查询:esExportAggregationDTO:{}", JSON.toJSONString(esExportAggregationDTO));
        Response<EsScrollReturnDTO> response = salesPlanEsRemote.exportByGroup(esExportAggregationDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
